<template>
  <div class="item-box">
    <div class="item-firstLine">
      <span>热门内容</span>
      <span>来自:<em style="cursor: pointer;">{{itemData.titles}}</em></span>
      <span class="item-close" style="cursor: pointer;">
        <i class="el-icon-close"></i>
      </span>
    </div>
    <div class="item-author">
      <div class="author-avatar">
        <img :src="itemData.avatar"/>
      </div>
      <div class="author-name" style="cursor: pointer;">{{itemData.titles}}</div>
      <div class="author-intor">{{itemData.lastreplytime}}</div>
      <!--唱别久悲不成悲,十分红处竟成灰-->
    </div>
    <div class="item-info">
      <div class="info-img" style="cursor: pointer;">
        <img :src="itemData.imgUri"/>
      </div>
      <div class="info-intro" style="cursor: pointer;" @click="_openDetail(itemData.id)">
        {{itemData.simplecontent}}
      </div>
    </div>
    <div class="item-fun">
      <div class="item-suggest">
        <div
          class="item-suggest-up"
          :class="[ isHover ? 'animated bounceIn' : '', isCountUp ? 'isCount' : '' ]"
          @click="suggestUpClickHandler"
          style="cursor: pointer;">
          <i class="el-icon-caret-top"></i>
          想看
          <em>{{itemData.favor}}</em>
        </div>
        <div
          class="item-suggest-down"
          :class=" [ isShake ? 'animated tada' : '', isCountDown ?  'isCount'　:　'' ] "
          @click="suggestDownClickHandler"
          style="cursor: pointer;">
          <i class="el-icon-caret-bottom"></i>
        </div>
      </div>
      <div class="funs-list">
        <span style="cursor: pointer;"><i class="el-icon-view"></i><em style="margin-right: 5px">{{itemData.repleycount}}</em>条评论</span>
        <span style="cursor: pointer;"><i class="el-icon-share"></i>分享</span>
        <span style="cursor: pointer;"><i class="el-icon-star-on"></i>收藏</span>
        <span style="cursor: pointer;"><i class="el-icon-more"></i></span>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  name: "item-box",
  props: {
    itemData: {
      type: Object
    }
  },
  data () {
    return {
      isHover: false,
      isShake: false,
      isCountDown: false,
      isCountUp: false
    }
  },
  methods: {
    _openDetail (val) { // 打开详情
      this.$emit('openDetail', val)
    },
    suggestUpClickHandler () { // 点赞处理事件
      this._addFavor({forumid: this.itemData._id})
        .then((res) => {
          console.log(res)
          this.isHover = true
          this.isCountUp = !this.isCountUp
          this.suggestStatusUp()
        })
        .catch((err) => {
          console.log(err)
        })
      setTimeout(() => {
        this.isHover = false
      }, 1000)
    },
    suggestDownClickHandler () { // 拉黑处理事件
      this._removeFavor({forumid: this.itemData._id})
        .then((res) => {
          console.log(res)
          this.isShake = true
          this.isCountDown = !this.isCountDown
          this.suggestStatusDown()
        })
        .catch((err) => {
          console.log(err)
        })
      setTimeout(() => {
        this.isShake = false
      }, 1000)
    },
    suggestStatusUp () { // 点击赞关闭拉黑
      if (this.isCountUp && this.isCountDown) {
        this.isCountDown = false
        return false
      }
    },
    suggestStatusDown () { // 点击拉黑关闭赞
      if (this.isCountUp && this.isCountDown) {
        this.isCountUp = false
        return false
      }
    },
    ...mapActions(['_addFavor', '_removeFavor'])
  }
}
</script>

<style scoped lang="less">
.item-box{
  min-width: 521px;
  padding: 16px 20px;
  margin-bottom: 20px;
  background: #fff;
  overflow: hidden;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(26,26,26,.1);
  box-sizing: border-box;
  .item-firstLine{
    color: #8590a6;
    margin-bottom: 8px;
    .item-close{
      float: right;
    }
  }
  .item-author{
    margin-bottom: 14px;
    overflow: hidden;
    &>div{
      float: left;
    }
    .author-avatar{
      width: 24px;
      height: 24px;
      background: #aaa;
      overflow: hidden;
      margin-right: 14px;
      img{
        width: 100%;
      }
    }
    .author-name{
      font-size: 15px;
      margin-right: 20px;
      line-height: 30px;
    }
    .author-intor{
      color: #646464;
      line-height: 30px;
    }
  }
  .item-info{
    min-height: 110px;
    margin: 6px 0px;
    padding: 6px 0px;
    overflow: hidden;
    position: relative;
    .info-img{
      overflow: hidden;
      position: absolute;
      top: 0;
      left: 0;
      float: left;
      background: #eee;
      width: 190px;
      height: 105px;
      background-position: 50%;
      background-size: cover;
      border-radius: 4px;
      box-shadow: 0 1px 3px rgba(26,26,26,.1);
      img{
        width: 100%;
      }
    }
    .info-intro{
      float: left;
      padding-left: 210px;
      line-height: 1.67;
    }
  }
  .item-fun{
    &>div{
      float: left;
      line-height: 32px;
    }
    .item-suggest{
      height: 32px;
      line-height: 32px;
      &>div{
        padding: 0 12px;
        margin: 0 4px;
        border-radius: 4px;
        float: left;
        background: rgba(0,132,255,.1);
        color: #0084ff;
        i{
          color: #0084ff;
        }
      }
      .isCount{
        background-color: #0084ff;
        color: #ffffff;
        i{
          color: #ffffff;
        }
      }
    }
    .funs-list{
      margin-left: 40px;
      span{
        margin-right: 15px;
        color: #8590a6;
        i{
          margin-right: 5px;
        }
      }
    }
  }
}

</style>
